package phoenix.mob_android.test_objects;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import phoenix.core.PhoenixManager;
import phoenix.core.base.extensions.TestBaseMobAndroidExt;
import phoenix.core.data_models.UserProfileDataModel.LookingFor;
import phoenix.core.data_models.UserProfileDataModel.ProfileDetails;
import phoenix.mob_android.test_objects.data_providers.ProfileDataProviders;

public class ProfileTests extends TestBaseMobAndroidExt
{

	public ProfileTests(PhoenixManager p_phoenix)
	{
		super(p_phoenix);
	}

	// Data
	public ProfileDataProviders dataProviders = new ProfileDataProviders(manager);

	public void profileTest(ProfileDetails p_profileDetails, LookingFor p_profileLookingFor)
	{
		try
		{
			page().mainMenu().openMainMenu().openMyProfile();
			md().wait(5);
			if (manager.isFlirt())
			{
				page().profilePage().setDescriptionWithEditButton(p_profileLookingFor.description);
				page().profilePage().setHeightWithEditButton().setBodyWithEditButton().setOrientationWithEditButton().
						setMaritalStatusWithEditButton()
						.setSmokeWithEditButton().setDrinkWithEditButton().setChildrenWithEditButton();
				page().indexPage().clickBackAndroidButton();
				page().mainMenu().openMainMenu().openMyProfile().openSettings();
				page().settingsPage().clickLogoutButton();
			}
			if (manager.isWB() || manager.isCL())
			{
				page().profilePage().setDescriptionWithoutEditButton(p_profileLookingFor.description);
				page().profilePage().setHeightWithoutEditButton().setBodyWithoutEditButton().setOrientationWithoutEditButton()
						.setMaritalStatusWithoutEditButton().setSmokeWithoutEditButton().setDrinkWithoutEditButton().
						setChildrenWithoutEditButton();
				page().indexPage().clickBackAndroidButton();
				if (manager.isWB())
				{
					page().mainMenu().openMainMenu().openSettings();
				}
				if (manager.isCL())
				{
					page().mainMenu().openMainMenu().openMyProfile().openSettings();
				}
				page().settingsPage().clickLogoutButton();
			}
			page().indexPage().login(manager.testUser().getEmail(), manager.testUser().getPassword());
			if (manager.isFlirt())
			{
				page().searchPage().closeMobileNumberPopUp();
			}

			page().mainMenu().openMainMenu().openMyProfile();
			ArrayList<String> list_personalInfo = page().profilePage().getDescription();

			if (!list_personalInfo.get(0).equals(p_profileLookingFor.description))
			{
				log().errorAndScreen(
						"Description doesn't save correct  " + "saved value => " + list_personalInfo.get(0) + " " + " actual value => "
								+ p_profileLookingFor.description);
			}

			if (!list_personalInfo.get(1).equals(p_profileDetails.height))
			{
				log().errorAndScreen(
						"Height doesn't save correct  " + "saved value => " + list_personalInfo.get(1) + " " + " actual value => "
								+ p_profileDetails.height);
			}

			if (!list_personalInfo.get(2).equals(p_profileDetails.bodyType))
			{
				log().errorAndScreen(
						"Body type doesn't save correct  " + "saved value => " + list_personalInfo.get(2) + " " + " actual value => "
								+ p_profileDetails.bodyType);
			}

			if (!list_personalInfo.get(3).equals(p_profileDetails.orientation))
			{
				log().errorAndScreen(
						"Orientation doesn't save correct  " + "saved value => " + list_personalInfo.get(3) + " " + " actual value => "
								+ p_profileDetails.orientation);
			}

			if (!list_personalInfo.get(4).equals(p_profileDetails.maritalStatus))
			{
				log().errorAndScreen(
						"Marital status doesn't save correct  " + "saved value => " + list_personalInfo.get(4) + " " + " actual value => "
								+ p_profileDetails.maritalStatus);
			}

			if (!list_personalInfo.get(5).equals(p_profileDetails.smoke))
			{
				log().errorAndScreen(
						"Smoke doesn't save correct  " + "saved value => " + list_personalInfo.get(5) + " " + " actual value => "
								+ p_profileDetails.smoke);
			}

			if (!list_personalInfo.get(6).equals(p_profileDetails.drink))
			{
				log().errorAndScreen(
						"Drink doesn't save correct  " + "saved value => " + list_personalInfo.get(6) + " " + " actual value => "
								+ p_profileDetails.drink);
			}

			if (!list_personalInfo.get(7).equals(p_profileDetails.children))
			{
				log().errorAndScreen(
						"Children doesn't save correct  " + "saved value => " + list_personalInfo.get(7) + " " + " actual value => "
								+ p_profileDetails.children);
			}

		}
		catch (Exception p_ex)
		{
			log().errorAndScreen("Profile test error : " + p_ex.toString());
		}

		// Verifying result
		test().forErrors();
	}

	public void redirectPPProfileUpgradeButton(int p_numberProfile)
	{
		try
		{
			page().mainMenu().openMainMenu().openSearch();
			page().searchPage().clickGridButton().openProfileFromGridSearch(p_numberProfile);
			if (manager.isFlirt() || manager.isCL())
			{
				page().profilePage().openAboutProfileInfo().clickUpgradeButton();
			}
			if (manager.isWB())
			{
				page().profilePage().clickUpgradeButton();
			}
			page().paymentPage().isOnPaymentPage();
			md().wait(5);
		}
		catch (Exception p_ex)
		{
			log().errorAndScreen("Profile upgrade button test error : " + p_ex.toString());
		}

		// Verifying result
		test().forErrors();
	}

	public void userProfilePageTest(int p_numberProfile, String p_message)
	{
		try
		{
			page().mainMenu().openMainMenu().openSearch();
			page().searchPage().clickSingleButton().openSearchParameters().submitSearchParameters();
			page().searchPage().clickGridButton().isOnGridSearchPage().openProfileFromGridSearch(p_numberProfile);
			if (manager.isFlirt() || manager.isCL())
			{
				page().profilePage().checkForBottomMenu().addUserToBlackList();
			}
			if (manager.isWB())
			{
				page().profilePage().addUserToBlackList();
			}
			String p_userScreenname = page().profilePage().getUserScreenname();
			if (manager.isFlirt() || manager.isCL())
			{
				page().mainMenu().openMainMenu().openMyProfile().openSettings();
			}
			if (manager.isWB())
			{
				page().mainMenu().openMainMenu().openSettings();
			}
			page().settingsPage().openBlackList();
			String p_userScreennameBlackList = page().settingsPage().getScreennameInBlackList();
			if (!p_userScreenname.equals(p_userScreennameBlackList))
			{
				log().errorAndScreen(
						"User screenname doesn't equals in the black list: user scrm => " + p_userScreenname + " user scrm from black list => "
								+ p_userScreennameBlackList);
			}
			page().settingsPage().openProfileFromBlackList();
			page().profilePage().addUserToBlackList();
			if (manager.isFlirt() || manager.isCL())
			{
				page().mainMenu().openMainMenu().openMyProfile().openSettings();
			}
			if (manager.isWB())
			{
				page().mainMenu().openMainMenu().openSettings();
			}
			page().settingsPage().openBlackList().checkForEmptyBlackList();
			page().mainMenu().openMainMenu().openSearch();
			page().searchPage().clickGridButton().openProfileFromGridSearch(p_numberProfile);
			page().profilePage().openPrivateChat();
			page().chatPage().isOnPrivateChatPage();

			Map<Integer, String[]> chatData = new HashMap<Integer, String[]>();
			chatData = page().chatPage().sendMessageToChatRoom(p_message);

			for (Map.Entry<Integer, String[]> entry : chatData.entrySet())
			{
				String data[] = entry.getValue();

				manager.test().assertEquals(data[0], manager.testUser().getScreenname(),
						"Chat screenname doesn't equals : get screenname => " + data[0] + " :actual screenname => " + manager.testUser().getScreenname());
				manager.test().assertEquals(data[1], p_message,
						"Text of the message doesn't equals : get text => " + data[1] + " :actual text => " + p_message);
			}
			page().indexPage().clickBackAndroidButton();
			page().mainMenu().openMainMenu().openSearch();
			page().searchPage().clickGridButton().openProfileFromGridSearch(p_numberProfile);
			page().profilePage().addUserToFavourite();
			page().mainMenu().openMainMenu().openFavourites();
			if (!page().favouritesPage().checkForFriends())
			{
				log().errorAndScreen("User doesn't added to favourites");
			}
			if (manager.isFlirt() || manager.isCL())
			{
				String p_screennameFromFavourites = page().favouritesPage().getScreennameOfFriend();
				if (!(p_userScreenname.equals(p_screennameFromFavourites)))
				{
					log().errorAndScreen(
							"User added from search => " + p_userScreenname + " doesn't equals user from favourites => " +
									p_screennameFromFavourites);
				}
			}
			page().favouritesPage().openProfile().removeFromFavourites();
			page().mainMenu().openMainMenu().openFavourites();
			if (page().favouritesPage().checkForFriends())
			{
				log().errorAndScreen("User doesn't remove from favourites");
			}
			page().indexPage().clickBackAndroidButton();
			page().profilePage().openAboutProfileInfo().isAboutDescriptionPresent();
		}
		catch (Exception p_ex)
		{
			log().errorAndScreen("User profile page test error : " + p_ex.toString());
		}

		// Verifying result
		test().forErrors();
	}
}
